/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DownloaderView.java
 *
 * Created on 2011-05-23, 08:55:08
 */
package ytmc.downloader;

import java.awt.Dialog.ModalityType;
import javax.swing.JOptionPane;
import ytmc.PanelView;

/**
 *
 * @author K
 */
public class DownloaderView extends PanelView
{
    private DownloaderModel model;
    private DownloaderController controller;
    private AddDownloadTaskView addDownloadTaskView;
    
    public String getSavePath()
    {
        return addDownloadTaskView.getSavePath();
    }

    public void setSavePath(String path)
    {
        addDownloadTaskView.setSavePath(path);
    }

    public String getDownloadURL()
    {
        return addDownloadTaskView.getDownloadURL();
    }

    public void setDownloadURL(String url)
    {
        addDownloadTaskView.setDownloadURL(url);
    }

    /** Creates new form DownloaderView */
    public DownloaderView( DownloaderController controller, DownloaderModel model )
    {
        this.model = model;
        this.controller = controller;
        this.addDownloadTaskView = new AddDownloadTaskView(controller);

        initComponents();

        downloadsTable.setModel(model);
        downloadsTable.getColumn("Wideo").setMinWidth(150);
        downloadsTable.getTableHeader().setReorderingAllowed(false);
    }

    public void showMessage(String message)
    {
        JOptionPane.showMessageDialog(this, message);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings( "unchecked" )
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        addDwonloadBtn = new javax.swing.JButton();
        removeDownloadBtn = new javax.swing.JButton();
        startDownloadBtn = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        downloadsTable = new javax.swing.JTable();

        setMinimumSize(new java.awt.Dimension(720, 400));
        setPreferredSize(new java.awt.Dimension(720, 400));

        jToolBar1.setFloatable(false);
        jToolBar1.setOrientation(1);
        jToolBar1.setRollover(true);
        jToolBar1.setMinimumSize(new java.awt.Dimension(40, 2));

        addDwonloadBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/assets/add24.png"))); // NOI18N
        addDwonloadBtn.setToolTipText("Dodaj wideo do pobrania");
        addDwonloadBtn.setFocusable(false);
        addDwonloadBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        addDwonloadBtn.setMaximumSize(new java.awt.Dimension(40, 31));
        addDwonloadBtn.setMinimumSize(new java.awt.Dimension(40, 31));
        addDwonloadBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        addDwonloadBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addDwonloadBtnActionPerformed(evt);
            }
        });
        jToolBar1.add(addDwonloadBtn);

        removeDownloadBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/assets/delete24.png"))); // NOI18N
        removeDownloadBtn.setToolTipText("Usuń zaznaczone wideo");
        removeDownloadBtn.setFocusable(false);
        removeDownloadBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        removeDownloadBtn.setMaximumSize(new java.awt.Dimension(40, 31));
        removeDownloadBtn.setMinimumSize(new java.awt.Dimension(40, 31));
        removeDownloadBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        removeDownloadBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeDownloadBtnActionPerformed(evt);
            }
        });
        jToolBar1.add(removeDownloadBtn);

        startDownloadBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/assets/play24.png"))); // NOI18N
        startDownloadBtn.setToolTipText("Uruchom pobieranie");
        startDownloadBtn.setFocusable(false);
        startDownloadBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        startDownloadBtn.setMaximumSize(new java.awt.Dimension(40, 31));
        startDownloadBtn.setMinimumSize(new java.awt.Dimension(40, 31));
        startDownloadBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        startDownloadBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startDownloadBtnActionPerformed(evt);
            }
        });
        jToolBar1.add(startDownloadBtn);

        downloadsTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "Wideo", "Status", "Rozmiar", "Postęp", "Prędkość", "Szacowane"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        downloadsTable.setGridColor(new java.awt.Color(204, 204, 204));
        jScrollPane1.setViewportView(downloadsTable);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 667, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void addDwonloadBtnActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_addDwonloadBtnActionPerformed
    {//GEN-HEADEREND:event_addDwonloadBtnActionPerformed
        addDownloadTaskView.setModalityType(ModalityType.APPLICATION_MODAL);
        addDownloadTaskView.clear();
        addDownloadTaskView.setVisible(true);
    }//GEN-LAST:event_addDwonloadBtnActionPerformed

    private void removeDownloadBtnActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_removeDownloadBtnActionPerformed
    {//GEN-HEADEREND:event_removeDownloadBtnActionPerformed
        controller.removeTask(downloadsTable.getSelectedRow());
    }//GEN-LAST:event_removeDownloadBtnActionPerformed

    private void startDownloadBtnActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_startDownloadBtnActionPerformed
    {//GEN-HEADEREND:event_startDownloadBtnActionPerformed
        controller.startTask(downloadsTable.getSelectedRow());
    }//GEN-LAST:event_startDownloadBtnActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addDwonloadBtn;
    private javax.swing.JTable downloadsTable;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JButton removeDownloadBtn;
    private javax.swing.JButton startDownloadBtn;
    // End of variables declaration//GEN-END:variables
}
